Use TypeVar to help with QObject.findChild[ren]()#58
Merged
altendky merged 9 commits intopython-qt-tools:masterfrom Oct 2, 2020
Merged
Use TypeVar to help with QObject.findChild[ren]()#58altendky merged 9 commits intopython-qt-tools:masterfrom
altendky merged 9 commits intopython-qt-tools:masterfrom
Conversation
Collaborator
Author
|
I'm looking into the ones that take tuples of types, but if you know how to handle it... |
Collaborator
Author
|
This is disgusting but I don't know of a better way yet. Maybe it's worth skipping the tuple-taking overloads. https://repl.it/@altendky/CalmSickDistributeddatabase-1 import string
upper_letters = ['T' + c for c in string.ascii_uppercase]
def create_typevars(
names=upper_letters,
typevar='typing.TypeVar',
bound=None,
):
if bound is None:
bound_argument = ''
else:
bound_argument = f', bound={bound}'
return [
f'{name} = {typevar}("{name}"{bound_argument})'
for name in names
]
def main():
names = upper_letters[:4]
print('\n'.join(create_typevars(names=names, bound='QObject')))
template = 'def findChildren(self, types: typing.Tuple[{0}], name: str = ..., options: typing.Union[Qt.FindChildOptions, Qt.FindChildOption] = ...) -> typing.List[typing.Union[{0}]]: ...'
for index in range(len(names)):
print(template.format(', '.join(names[:index + 1])))
main() |
This was referenced Sep 13, 2020
Collaborator
Author
|
Kick CI |
Collaborator
Author
Collaborator
Author
|
Maybe I'll come back and do that fancy generated variadic generics stuff but... I think it is at least good to keep that separate regardless. |
BryceBeagle
requested changes
Oct 2, 2020
BryceBeagle
approved these changes
Oct 2, 2020
bluebird75
pushed a commit
to bluebird75/PyQt5-stubs
that referenced
this pull request
Aug 24, 2021
Use TypeVar to help with QObject.findChild[ren]()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

No description provided.